﻿<UserControl x:Class="TheSnakeGame.WpfClient.Views.GameField"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:vms="clr-namespace:TheSnakeGame.WpfClient.ViewModels"
             d:DesignHeight="800" d:DesignWidth="800">
    <UserControl.DataContext>
        <vms:GameEngineViewModel/>
    </UserControl.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBlock Text="{Binding Title}" Grid.Row="0"/>

        <ItemsControl Grid.Row="1" ItemsSource="{Binding Walls}" Name="OuterWalls">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Canvas.Left" Value="{Binding Path=Left}"/>
                    <Setter Property="Canvas.Top" Value="{Binding Path=Top}"/>
                </Style>
            </ItemsControl.ItemContainerStyle>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Rectangle Width="{Binding Width}" Height="{Binding Height}"
                                           Fill="Red" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <Canvas Name="SnakeHead" Grid.Row="1">
            <Rectangle Width="{Binding Path=SnakeHead.Width}" Height="{Binding Path=SnakeHead.Height}" 
                       Fill="Green" 
                       Canvas.Top="{Binding Path=SnakeHead.Top}" 
                       Canvas.Left="{Binding Path=SnakeHead.Left}"/>
        </Canvas>
        
        <ItemsControl Grid.Row="1" ItemsSource="{Binding SnakeBody}" Name="SnakeBody">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Canvas.Left" Value="{Binding Path=Left}"/>
                    <Setter Property="Canvas.Top" Value="{Binding Path=Top}"/>
                </Style>
            </ItemsControl.ItemContainerStyle>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Rectangle Width="{Binding Width}" Height="{Binding Height}"
                                           Fill="Blue" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</UserControl>
